package com.cqggrw.action;

import org.apache.struts2.ServletActionContext;

import com.cqggrw.domain.Json;
import com.cqggrw.domain.TPiao;
import com.cqggrw.service.TouPiaoServiceI;
import com.cqggrw.service.impl.TouPiaoServiceImpl;
import com.opensymphony.xwork2.ModelDriven;

public class TouPiaoAction extends BaseAction implements ModelDriven<TPiao> {

	private static final long serialVersionUID = 1L;
	
	private TouPiaoServiceI service = new TouPiaoServiceImpl();
	private TPiao tp = new TPiao();
	
	public String add() {
		String falg = "success";
		if(service.add(tp)) {
			super.addAttributeForRequest("message", "添加成功!");
		} else {
			super.addAttributeForRequest("message", "添加失败!");
		}
		
		return falg;
	}
	
	public void getList() {
		super.writeJson(service.get());
	}
	
	public String getTp() {
		super.addAttributeForRequest("tp", service.getTp(tp));
		return "getTp";
	}

	public TPiao getModel() {
		return tp;
	}
	
	public void modify() {
		service.modify(tp);
		Json json = new Json();
		json.setSuccess(true);
		super.writeJson(json);
	}
	
	public void del() {
		Integer id = Integer.parseInt(ServletActionContext.getRequest().getParameter("id"));
		service.del(id);
		Json json = new Json();
		json.setSuccess(true);
		json.setMsg("删除成功!");
		super.writeJson(json);
	}
	
	public void modifyOpt() {
		String name = ServletActionContext.getRequest().getParameter("name");
		Integer objId = Integer.parseInt(ServletActionContext.getRequest().getParameter("objId"));
		service.modifyOpt(objId, name);
		Json json = new Json();
		json.setSuccess(true);
		super.writeJson(json);
	}
	
	public void addOpt() {
		service.addOpt(tp.getId(), tp.getName());
	}
	
	public void delObj() {
		service.delObj(tp);
		Json json = new Json();
		json.setSuccess(true);
		json.setMsg("删除成功！");
		super.writeJson(json);
	}
	
	public void doToupiao() {
		Integer id = Integer.parseInt(ServletActionContext.getRequest().getParameter("id"));
		service.doToupiao(id);
	}

}
